package edu.oregonstate.vision.common;

import java.util.List;

public class EuclideanDistanceCalculator extends DistanceCalculator {

	@Override
	public DescriptorMatrix calculate(List<Point> p, List<Point> q) {
		DescriptorMatrix matrix = new DescriptorMatrix(p.size(), q.size());
		for (int i = 0; i < p.size(); i++) {
			for (int j = 0; j < q.size(); j++) {
				Point pI = p.get(i);
				Point qJ = q.get(j);
				matrix.set(
						i,
						j,
						Math.sqrt(Math.pow(qJ.getX() - pI.getX(), 2)
								+ Math.pow(qJ.getY() - pI.getY(), 2)
								+ Math.pow(qJ.getZ() - pI.getZ(), 2)));
			}
		}
		return matrix;
	}

	private static EuclideanDistanceCalculator euclideanDistanceCalculator;

	public static DistanceCalculator getInstance() {
		if (euclideanDistanceCalculator == null)
			euclideanDistanceCalculator = new EuclideanDistanceCalculator();
		return euclideanDistanceCalculator;
	}
}
